package ${package.Service};

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import com.syscom.common.mapper.${table.mapperName};
import com.syscom.common.base.BasePage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.syscom.common.utils.result.AjaxResult;
import com.syscom.common.utils.result.ResultTool;
import com.syscom.common.entity.${entity};
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.util.StringUtils;
/**
* @author ${author}
* @date ${date}
*/
@Slf4j
@Service
public class ${table.serviceName}  {

    @Autowired
    private ${table.mapperName} ${lowerMapperName};

    public AjaxResult query${entity}(BasePage basePage<#if queryObj??><#list queryObj?keys as key>, String ${key}</#list></#if>) {

        Page<${entity}> page = new Page<>(basePage.getPageNo(), basePage.getPageSize());
        QueryWrapper<${entity}> queryWrapper = new QueryWrapper<>();
        <#if queryObj??><#list queryObj?keys as key>
        queryWrapper.eq(!StringUtils.isEmpty(${key}), "${key}", ${key});
        </#list></#if>
        queryWrapper.orderByAsc("object_id");
        return ResultTool.success(${lowerMapperName}.selectPage(page, queryWrapper));
    }

    public AjaxResult add${entity}(${entity} ${lowerEntityName}) {

        return ResultTool.success(${lowerMapperName}.insert(${lowerEntityName}));
    }

    public AjaxResult update${entity}(${entity} ${lowerEntityName}){

        return ResultTool.success(${lowerMapperName}.updateById(${lowerEntityName}));
    }

    public AjaxResult delete${entity}(Long objectId){

        return ResultTool.success(${lowerMapperName}.deleteById(objectId));
    }
}

